<?
require_once("../config/dbconn.php");require_once("../config/usercls.php");require_once("pwd1cls.php");

if($glo_closebdtobd==1){	
echo "<script>alert('内部转账已经关闭！\\n');location.href='announce_lst.php';</script>";
	exit();
}
$sqlhy="select * from {$db_prefix}users where id='".$_SESSION['sys_userid']."'";
$rshy=$db->get_one($sqlhy);

if($act=='transdo'){
	$msg='';
	if(trim($tousername)=='') $msg.="请输入转给会员\\n";
	else{
		if($_SESSION['sys_username']==trim($tousername)) $msg.="不能转给自己\\n";
	}
	if(floatval($price)<=0) $msg.="请输入转账金额\\n";
	else{
	   /* echo "<script>alert('$ptype');</script>";
		echo "<script>alert('$glo_dzbzyxblower');</script>";
		echo "<script>alert('$glo_jjzdzblower');</script>";*/
		if($ptype==1){
			if(floatval($price)<$glo_dzbzyxblower) $msg.="金额不能低".$glo_dzbzyxblower."\\n";
			else{
				if ((floatval($price)%$glo_nbbs)>0){
					$msg.="金额必须是{$glo_nbbs}的倍数\\n";
				}
			}
		}
		if($ptype==5){
			if(floatval($price)<$glo_jjzdzblower) $msg.="金额不能低于低".$glo_dzbzyxblower."\\n";
			else{
				if ((floatval($price)%$glo_nbbs)>0){
					$msg.="金额必须是{$glo_nbbs}的倍数\\n";
				}
			}
		}		
	}
	if ($msg!=''){
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
	
	//如果没有扣除网络维护费。不能转账
	/*$sqlwhf="select * from {$db_prefix}yearf where userid='".$_SESSION['sys_userid']."'";
	$rswhf=$db->get_one($sqlwhf);
	if (!$rswhf['id']){
		 $msg.="没有扣除网络维护费。不能转账\\n";
	}
	if ($msg!=''){
		echo "<script>alert('$msg');history.back();</script>";exit();
	}*/
	
	//转给会员是否存在
	$sqlhy1="select * from {$db_prefix}users where username='".trim($tousername)."'";
	$rshy1=$db->get_one($sqlhy1);
	if (!$rshy1['id']) $msg.="转给会员不存在\\n";
	if ($msg!=''){
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
	$touserid=$rshy1['id'];
	
	$feiyong=0;
	$feiyong=floatval($price)*$glo_zztransrate/100;
	$realprice=floatval($price)-$feiyong;
	if ($ptype==1){
		if ($rshy['price']<$price) $msg.="您的报单币金额不足{$price}人民币\\n";
	}
	if ($ptype==5){
		if ($rshy['gwprice']<$price) $msg.="您的购物账户金额不足{$price}人民币\\n";
	}
	if ($ptype==3){
		if ($rshy['jjprice']<$price) $msg.="您的奖金账户金额不足{$price}人民币\\n";
	}
	
	if ($msg!=''){
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
	//转账开始
	if ($ptype==1){
		$sqlkk="update {$db_prefix}users set price=price-'".floatval($price)."' where id='".$_SESSION['sys_userid']."'";
		$sqlkk1="update {$db_prefix}users set price=price+'".floatval($realprice)."' where username='".trim($tousername)."'";
	}
	if ($ptype==5){
		$sqlkk="update {$db_prefix}users set gwprice=gwprice-'".floatval($price)."' where id='".$_SESSION['sys_userid']."'";
		$sqlkk1="update {$db_prefix}users set gwprice=gwprice+'".floatval($realprice)."' where username='".trim($tousername)."'";
	}
	if ($ptype==3){
		$sqlkk="update {$db_prefix}users set jjprice=jjprice-'".floatval($price)."' where id='".$_SESSION['sys_userid']."'";
		$sqlkk1="update {$db_prefix}users set jjprice=jjprice+'".floatval($realprice)."' where username='".trim($tousername)."'";
	}
	$db->query($sqlkk);$db->query($sqlkk1);
	//财务记录
	$e_userid=$_SESSION['sys_userid'];$e_price=-floatval($price);$e_type=10;$e_ptype=$ptype;$e_addtime=$curtime;$e_memo="转给{$tousername}";
	hyepricejl($e_userid,$e_price,$e_type,$e_ptype,$e_addtime,$e_memo);
	$e_userid=$touserid;$e_price=$realprice;$e_type=9;$e_ptype=$ptype;$e_addtime=$curtime;$e_memo="{$_SESSION['sys_username']}转入";
	hyepricejl($e_userid,$e_price,$e_type,$e_ptype,$e_addtime,$e_memo);
	
	//插入数据库
	$dataArray['username']=$_SESSION['sys_username'];
	$dataArray['tousername']=trim($tousername);
	$dataArray['price']=floatval($realprice);
	$dataArray['feiyong']=$feiyong;
	$dataArray['memo']=addslashes($memo);
	$dataArray['ptype']=$ptype;
	$dataArray['addtime']=$curtime;
	$db->insert("{$db_prefix}transferzz",$dataArray);
	echo "<script>alert('转账成功');location.href='trans_zz.php';</script>";exit();
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
		background-image: url(image1/bg-body.png);	
}
.red{
	color:#FF0000
}

-->
</style>

<link href="images/skin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="29" valign="top" background="images/mail_leftbg1.png"><img src="images/left-top-right1.png" width="17" height="29" /></td>
    <td width="100%" height="29" valign="top" background="images/content-bg.png"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">财务转账/Financial transfers</div></td>
      </tr>
    </table></td>
    <td width="16" valign="top" background="images/mail_rightbg.png"><img src="images/nav-right-bg.png" width="16" height="29" /></td>
  </tr>
  <tr>
    <td height="71" valign="middle" background="images/mail_leftbg1.png">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9"><table width="100%" height="138" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="13" valign="top">&nbsp;</td>
      </tr>
      <tr>
        <td valign="top">
		<form id="form1" name="form1" method="post" action="?act=transdo">
		<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#F7F8F9">
		<tbody bgcolor="#FFFFFF">
            <tr>
              <td colspan="3"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="nowtable">
                <tr>
                  <td class="left_bt2">&nbsp;&nbsp;&nbsp;&nbsp;您的报单币余额：
                    <?=$rshy['price']?>人民币/RMB. 奖金账户余额：<?=$rshy['jjprice']?>人民币/RMB</td>
                </tr>
              </table></td>
            </tr>
            <tr>
              <td height="30" colspan="3">
			  
			  <table width="100%" height="120" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td height="30" align="center" class="left_txt">账户：</td>
                  <td height="30" class="left_txt"><label>
                    <select name="ptype">
                   <? if($glo_closebdtobd==0){?>
					<option value="1">报单币</option>      
                   <? }?> 
                   <? if($glo_closejjto==0) {?>                               
                    <option value="5">购物券</option> 
                   <? }?> 
                   <!-- <option value="4">税金</option>  -->
                    </select>
                  </label></td>
                </tr>
                <tr>
                  <td height="30" align="center" class="left_txt">转给会员：</td>
                  <td height="30" class="left_txt"><label>
                    <input name="tousername" type="text" id="tousername">
                    <span class="red">* 输入会员编号/Enter the User ID</span></label></td>
                </tr>
                <tr>
                  <td height="30" align="center" class="left_txt">金额：</td>
                  <td height="30" class="left_txt"><label>
                    <input name="price" type="text" id="price" size="10" value="<?=$rs['price']?>">
                    人民币/RMB. ￥
                    <span class="red">*,最小金额 <?=$glo_dzbzyxblower?> 元，且必须是<?=$glo_nbbs?>的倍数。 <? if ($glo_zztransrate>0) {?>财务转账手续费/Financial transfer fee：<?=$glo_zztransrate?>%<? }?></span></label></td>
                </tr>
				   <tr>
                  <td height="30" align="center" class="left_txt">说明：</td>
                  <td height="30" class="left_txt"><label>
                    <textarea name="memo" cols="40" rows="6" id="memo"><?=stripslashes($rs['memo'])?></textarea>
                  </label></td>
                </tr>
              </table></td>
            </tr>
            
            <tr>
              <td height="30" colspan="3">&nbsp;</td>
            </tr>
            <tr>
              <td width="50%" height="30" align="right"><input type="submit" value="确定转账" name="B1" /></td>
              <td width="6%" height="30" align="right">&nbsp;</td>
              <td width="44%" height="30"><input type="reset" value="取消设置" name="B12" /></td>
            </tr>
            <tr>
              <td height="30" colspan="3">&nbsp;</td>
            </tr>
			</tbody>
          </table>
		  </form>
		  </td>
      </tr>
    </table></td>
    <td background="images/mail_rightbg.png">&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.png"><img src="images/buttom_left2.png" width="17" height="17" /></td>
      <td height="17" valign="top" background="images/buttom_bgs.png"><img src="images/buttom_bgs.png" width="17" height="17" /></td>
    <td background="images/mail_rightbg.png"><img src="images/buttom_right2.png" width="16" height="17" /></td>
  </tr>
</table>

</body>
</html>